using System;
using System.Collections;
using XISoft.AppCreator.Util.ICodeCreator;

namespace XISoft.AppCreator.CSharpCodeCreator
{
	/// <summary>
    /// The channel of type change between SQLServer and CSharp
	/// </summary>
	public class TypeHelper:ITypeHelper
	{
		public TypeHelper()
		{
		}
        /// <summary>
        /// Read SQLServer data from CodeCeater and change type
        /// </summary>
        /// <param name="SqlType"></param>
        /// <returns></returns>
        public string DBtoLanguage(string SqlType)
		{
			string CSharpType="System.Object";
            switch (SqlType.ToLower())
			{
				case "varchar":
					CSharpType="System.String";
					break;
				case "bigint":
					CSharpType="System.Int64";
					break;
				case "binary":
					CSharpType="System.IO.Stream";
					break;
				case "bit":
					CSharpType="System.Int32";
					break;
				case "char":
					CSharpType="System.String";
					break;
				case "cursor":
					break;
				case "datetime":
					CSharpType="System.DateTime";
					break;
				case "decimal":
					CSharpType="System.Double";
					break;
				case "image":
					CSharpType="System.IO.Stream";
					break;
				case "float":
					CSharpType="System.Single";
					break;
				case "int":
					CSharpType="System.Int32";
					break;
				case "money":
					CSharpType="System.Double";
					break;
				case "nchar":
					CSharpType="System.String";
					break;
				case "ntext":
					CSharpType="System.String";
					break;
				case "numeric":
					CSharpType="System.Double";
					break;
				case "nvarchar":
					CSharpType="System.String";
					break;
				case "rowversion":
					break;
				case "real":
					CSharpType="System.Double";
					break;
				case "smalldatetime":
					CSharpType="System.DateTime";
					break;
				case "smallint":
					CSharpType="System.Int16";
					break;
				case "smallmoney":
					CSharpType="System.Double";
					break;
				case "sql_variant":
					CSharpType="System.Object";
					break;
				case "table":
					break;
				case "sysname":
					break;
				case "text":
					CSharpType="System.String";
					break;
				case "timestamp":
					break;
				case "tinyint":									
					CSharpType="System.Int16";
					break;
				case "uniqueidentifier":
					break;
				case "varbinary":
					CSharpType="System.IO.Stream";
					break;
				default:
					CSharpType="System.Object";
					break;					
			}
			return CSharpType;
		}
        /// <summary>
        /// Change C# to SQlServer data type
        /// </summary>
        /// <param name="SharpType"></param>
        /// <returns></returns>
        public string LanguageToDB(string LanguageType)
		{
			string sqlType="";
            switch (LanguageType)
			{
				case "System.Int32":
					sqlType= "int";
					break;
				case "System.String":
				sqlType= "varchar";
					break;
				case "System.Double":
					sqlType="";
					break;
			}
			return sqlType;
		}


    }
}
